/*=========================================================================
Elite College as Engines of Upward Mobility: Evidence from Colombia's Ser Pilo Paga
Authors: Juliana Londoño-Vélez, Catherine Rodriguez, Fabio Sánchez
and Luis Esteban Álvarez-Arango

Creation date: June 6th, 2025
--------------------------------------------------------------------------
Table A5
=========================================================================*/
	
use "${data}/data_RD", clear
keep if icfes_per==20132 | icfes_per==20142
	
global controls "icfes_student icfes_female icfes_age ethnminority icfes_works family_size icfes_educm1 icfes_educm2 icfes_educm3 icfes_educm4 icfes_educp1 icfes_educp2 icfes_educp3 icfes_educp4 icfes_stratum1 icfes_stratum2 icfes_stratum3 icfes_stratum4 icfes_stratum5 icfes_stratum6 icfes_schoolsch1 icfes_schoolsch2 icfes_schoolsch3 icfes_schoolsch4 icfes_schoolsch5 icfes_privatehs school_schedule_a school_schedule_b school_schedule_other floors_1 floors_2 floors_3 floors_4 family_internet family_laptop family_car family_cell_phone student_resides_urban school_urban"
global running_saber11 "running_saber11 if eligible_sisben==1 & icfes_per==20142"
global running_sisben "running_sisben if eligible_saber11==1 & icfes_per==20142"
	
foreach var of varlist graduation_exam_7 graduation_exam_pro_7 mw_8 mw_9 score_saberpro_5 score_saberpro_7{
	reg `var' $controls if icfes_per==20132
	predict `var'_hat, xb
}
	
matrix results = J(8,6,.)
local rr = 0
foreach r in saber11 sisben{
	local oo = 0
	foreach o in graduation_exam_7 graduation_exam_pro_7 mw_8 mw_9 score_saberpro_5 score_saberpro_7{
		if regexm("`o'","graduation") rdrobust `o'_hat ${running_`r'}, masspoints(off)
		if !regexm("`o'","graduation") rdrobust `o'_hat ${running_`r'} & score_saberpro_7!=., masspoints(off)
		matrix results[1+`rr',1+`oo']=round(e(tau_cl),0.0001)
		matrix results[2+`rr',1+`oo']=round(e(se_tau_cl),0.0001)
		matrix results[3+`rr',1+`oo']=round(e(ci_l_rb),0.0001)
		matrix results[4+`rr',1+`oo']=round(e(ci_r_rb),0.0001)
		local oo = `oo'+1
	}
	local rr = `rr'+4
}

matrix list results
svmat results
keep results*
drop if _n>8
rename results1 graduation_exam_7
rename results2 graduation_exam_pro_7
rename results3 mw_8
rename results4 mw_9
rename results5 score_saberpro_5
rename results6 score_saberpro_7
	
gen v1=""
replace v1="Coef sb11" in 1
replace v1="SE sb11" in 2
replace v1="CI BC left sb11" in 3
replace v1="CI BC right sb11" in 4
replace v1="Coef sisben" in 5
replace v1="SE sisben" in 6
replace v1="CI BC left sisben" in 7
replace v1="CI BC right sisben" in 8
order v1
drop graduation_exam_7 graduation_exam_pro_7 mw_8 mw_9
export excel using "${outcomes}/Tab_A5.xlsx", replace firstrow(variables)
	
	
	
